package com.googlecode.maratische.google.gui;

import static com.googlecode.maratische.google.MainController.getMainController;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import com.googlecode.maratische.google.MainController;

public class LinkLabel extends JLabel implements MouseListener {

	private String url = null;

	public void setFontSize(int size) {
		Font font = this.getFont();
		Font newFont = new Font(font.getName(), font.getStyle(), size);
		this.setFont(newFont);
	}
	
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public LinkLabel() {
		super();
		
		setCursor(new Cursor(Cursor.HAND_CURSOR));
		addMouseListener(this);
	}

	private static final long serialVersionUID = -8771290762320013237L;
	public String getBundleMessage(String message) {
		return getMainController().getBundleMessage(message);
	}

	public void mouseClicked(MouseEvent e) {
		mouseEvent(e);
	}

	public void mouseEntered(MouseEvent e) {
		setForeground(new Color(255, 0, 0));
		setToolTipText(this.url);
	}

	public void mouseExited(MouseEvent e) {
		setForeground(new Color(0, 0, 0));
		setToolTipText(null);
	}

	private void mouseEvent(MouseEvent e) {
		try {
			MainController.getMainController().openInBrowserSelectItem();
		} catch (Exception e1) {
			MainController.getMainController().showError("Ошибка при открытии браузера",e1);
		}
	}
	
	public void mousePressed(MouseEvent e) {
	}

	public void mouseReleased(MouseEvent e) {
	}

}
